#include "StdAfx.h"
#include "MainMenu.h"

CMainMenu::CMainMenu(void)
{

}

CMainMenu::~CMainMenu(void)
{

}

UINT CMainMenu::GetClassStyle()
{
	return WS_SYSMENU | WS_POPUP;
}

LPCTSTR CMainMenu::GetWindowClassName() const
{
	return _T("kanmm_window");
}

CDuiString CMainMenu::GetSkinFolder()
{
	return CDuiString(CPaintManagerUI::GetInstancePath()) + _T("skin\\");
}

CDuiString CMainMenu::GetSkinFile()
{
	return _T("mainmenu.xml");
}

void CMainMenu::AdjustPostion(int x, int y) {
	CDuiRect rcWnd;
	GetWindowRect(m_hWnd, &rcWnd);
	int nWidth = rcWnd.GetWidth();
	int nHeight = rcWnd.GetHeight();

	CDuiRect rcTrayWnd;
	GetTrayWndRect(rcTrayWnd);

	rcWnd.left = x /*- nWidth*/;
	int h = rcTrayWnd.GetHeight();
	rcWnd.top =  y - nHeight;
	rcWnd.right = rcWnd.left + nWidth;
	rcWnd.bottom = rcWnd.top + nHeight;

	MONITORINFO oMonitor = {};
	oMonitor.cbSize = sizeof(oMonitor);
	::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor);
	CDuiRect rcWork = oMonitor.rcWork;

	if( rcWnd.bottom > rcWork.bottom ) {
		if( nHeight >= rcWork.GetHeight() ) {
			rcWnd.top = 0;
			rcWnd.bottom = nHeight;
		}
		else {
			rcWnd.bottom = rcWork.bottom;
			rcWnd.top = rcWnd.bottom - nHeight;
		}
	}
	if( rcWnd.right > rcWork.right ) {
		if( nWidth >= rcWork.GetWidth() ) {
			rcWnd.left = 0;
			rcWnd.right = nWidth;
		}
		else {
			rcWnd.right = rcWork.right;
			rcWnd.left = rcWnd.right - nWidth;
		}
	}
	MoveWindow(m_hWnd,rcWnd.left, rcWnd.top, rcWnd.GetWidth(), rcWnd.GetHeight(),TRUE);
	//::SetWindowPos(m_hWnd, NULL, rcWnd.left, rcWnd.top, rcWnd.GetWidth(), rcWnd.GetHeight(), SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
}

BOOL CMainMenu::GetTrayWndRect(RECT& rect)
{
	HWND hTrayWnd= FindWindow(_T("Shell_TrayWnd"), _T(""));
	RASSERT(hTrayWnd , FALSE);
	return GetWindowRect(hTrayWnd,&rect);
}